﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ArtMath
{
    public class clsGS : clsFormulaBase
    {
        clsFormulaBase bkfs, gzs;
        public clsGS(PictureBox pb, clsFormulaBase gzs, clsFormulaBase bkfs) : base(pb)
        {
            BKFS = bkfs;
            GZS = gzs;
            Size = new SizeD(bkfs.Size.Width * 1.5f + gzs.Size.Width, Math.Max(bkfs.Size.Height + 6, (bkfs.Size.Height + 6) / 2 + gzs.Size.Height));
        }
        public clsFormulaBase GZS//根指数
        {
            get { return gzs; }
            set
            {
                gzs = value;
                picturebox.Invalidate();
            }
        }
        public clsFormulaBase BKFS//被开方数
        {
            get { return bkfs; }
            set
            {
                bkfs = value;
                picturebox.Invalidate();
            }
        }
        public override void setChildLocation()
        {
            gzs.Location = new PointD(Location.X, Location.Y);
            bkfs.Location = new PointD(Right - bkfs.Size.Width - 2, Bottom - bkfs.Size.Height - 2);
        }
        public override void Paint(Graphics gra)
        {
            bkfs.Paint(gra);
            gzs.Paint(gra);
            gra.DrawLines(new Pen(Color.Black, 2), new PointF[] { new PointF((float)gzs.Right+ 1, (float)(Location.Y+Size.Height * 0.64)),
                new PointF((float)(gzs.Right+(Size.Width - bkfs.Size.Width-gzs.Size.Width) * 0.2), (float)(Location.Y+Size.Height * 0.6)),
                new PointF((float)(gzs.Right+(Size.Width - bkfs.Size.Width-gzs.Size.Width) * 0.6), (float)Bottom),
                new PointF((float)(gzs.Location.X+Size.Width - bkfs.Size.Width), (float)Location.Y+1),
                new PointF((float)Right, (float)Location.Y+1) });
            base.Paint(gra);
        }
        public override string ToString()
        {
            return "sqrt(" + bkfs + ")";
        }
    }
}
